- 
                Notifications
    You must be signed in to change notification settings 
- Fork 445
Fix module recursive lookup bug #1130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|  | ||
| assert_equal [i1_m1, i1_m2, i1_m3, i1_m4, i1_k0_m4], m1_k1.includes | ||
| assert_equal [m1_m2_k0_m4, m1_m2_m3_m4, m1_m2_m3, m1_m2, m1, @object, | ||
| assert_equal [m1_m2_k0_m4, m1_m2_m4, m1_m3, m1_m2, m1, @object, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test was wrong.
Actual Mod1::Klass1.ancestors is
[Mod1::Klass1, Mod1::Mod2::Klass0::Mod4, Mod1::Mod2::Mod4, Mod1::Mod3, Mod1::Mod2, Mod1, Object, Kernel, BasicObject]module Mod1
  module Mod3
  end
  module Mod2
    module Mod3
      module Mod4
      end
    end
    module Mod4
    end
    class Klass0
      module Mod4
        # module Mod5
        # end
        module Mod6
        end
      end
      module Mod5; end
      include Mod4
      include Mod5
      include Mod6
      include Mod1
      include Mod2
      include Mod3
    end
  end
  class Klass1
    include Mod1
    include Mod2
    include Mod3
    include Mod4
    include Klass0::Mod4
  end
end
p Mod1::Klass1.ancestors
# Actual
#=> [Mod1::Klass1, Mod1::Mod2::Klass0::Mod4, Mod1::Mod2::Mod4,      Mod1::Mod3,       Mod1::Mod2, Mod1, Object, Kernel,    BasicObject]
# Test was expecting
#=> [(omitted),    Mod1::Mod2::Klass0::Mod4, Mod1::Mod2::Mod3,Mod4, Mod1::Mod2::Mod3, Mod1::Mod2, Mod1, Object, (omitted), BasicObject]5da426b    to
    47a40af      
    Compare
  
    | full_name = nesting.child_name(name) | ||
| mod = @store.modules_hash[full_name] | ||
| return mod if mod | ||
| nesting = nesting.parent | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that this part is not correct. should use Module.nesting instead of CodeObject#parent chain.
- while nesting
-   ...
-   nesting = nesting.parent
- end
+ unavailable_data.module_nesting.each do
+   ...
+ endBut I think RDoc::Include and RDoc::Extend does not provide enough information.
This pull request and the original implementation uses CodeObject#parent chain instead of module nesting.
Complicated example
class ::A
  class ::B
    class ::A
      class ::B::C
        # Module.nesting is [::B::C, ::A, ::B, ::A]
        include X
      end
    end
  end
end| Closing this because I think we need to do #1291 rather this pull request. And this pull request might not be the right way. | 
Fixes this bug
What was wrong with constant lookup implementation
Ruby's actual constant priority
document https://docs.ruby-lang.org/ja/latest/doc/spec=2fvariables.html#prio (Sorry, can't find the english version)